package com.example.demo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;

/**
 * 统一访问地址
 * Created by yuan on 2017/6/28.
 */
@RestController
public class HelloRibbonController {
    private static final Logger logger = LoggerFactory.getLogger(HelloRibbonController.class);

    @Value("${service.name}")
    private String serviceName;

    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/*")
    private String hello(HttpServletRequest request) {
        logger.info("请求地址:" + request.getRequestURL());
        String url = request.getRequestURI();
        String restUrl = this.serviceName + url;
        logger.info("重新拼装的请求地址:" + restUrl);
        return restTemplate.getForEntity(restUrl, String.class).getBody();
    }

}
